package factiva;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by zhongwei on 2016/12/28.
 */
public class ExportCSV {

    public static void main(String[] args) throws IOException {
        List<String> list = FileUtils.readLines(new File("management1.txt"));
        Pattern pattern = Pattern.compile(".+?\t道琼斯\\((.+?)\\)所有\\((.+?)\\)刊物 网页新闻\\((.+?)\\)博客\\((.+?)\\)图片\\((.+?)\\)多媒体\\((.+?)\\)", Pattern.DOTALL);
        for (String str : list) {
            String[] arr = str.split("\t");
            String period = arr[0];
            Matcher matcher = pattern.matcher(str);
            if (matcher.matches()) {
                System.out.print(period + "\t");
                System.out.print(matcher.group(1).replaceAll(",", "") + "\t");
                System.out.print(matcher.group(2).replaceAll(",", "") + "\t");
                System.out.print(matcher.group(3).replaceAll(",", "") + "\t");
                System.out.print(matcher.group(4).replaceAll(",", "") + "\t");
                System.out.print(matcher.group(5).replaceAll(",", "") + "\t");
                System.out.println(matcher.group(6).replaceAll(",", "") + "\t");
            } else {
                System.out.println(str);
            }
        }
    }
}
